﻿#region Usings

using System.Data.Entity.ModelConfiguration;
using Rail.Net.Core.Model;

#endregion

namespace Rail.Net.Data.Configuration
{
    public class StationMap : EntityTypeConfiguration<Station>
    {
        public StationMap()
        {
            ToTable("Stations");
            HasKey(station => station.Id);

            Property(station => station.Name).IsRequired().HasMaxLength(60);
            Property(station => station.Eva).IsRequired().HasMaxLength(7);
            Property(station => station.Epa).IsOptional().HasMaxLength(7);
            Property(station => station.Tisp).IsOptional().HasMaxLength(4);
            Property(station => station.ForSale).IsRequired();
            Property(station => station.X).IsOptional().HasMaxLength(15);
            Property(station => station.Y).IsOptional().HasMaxLength(15);
            Property(station => station.IsBorder).IsRequired();
            Property(station => station.BorderName).IsOptional().HasMaxLength(60);
            Property(station => station.BorderEva).IsOptional().HasMaxLength(7);
            Property(station => station.BorderCorrection).IsOptional();
            Ignore(station => station.AlternativeStation);

            HasRequired(station => station.Ru).WithMany(ru => ru.Stations);
            HasMany(station => station.Distances1).WithRequired(distance => distance.Station1);
            HasMany(station => station.Distances2).WithRequired(distance => distance.Station2);
            HasMany(station => station.RelationDescriptions).WithRequired(relationDescription => relationDescription.Station);
        }
    }
}